package com.maduar.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Description:
 *
 * @author danny.pang danny.pang@ebizprise.com
 * @date 2020-03-26 23:47
 */
public class JdkProxySubject implements InvocationHandler {

    private Object subject;

    public JdkProxySubject(Object subject) {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object result = null;
        System.out.println("before");

        try {
            result = method.invoke(subject, args);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("after");
        }
        return result;
    }
}
